package com.example.ui.homepage;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.TextView.BufferType;

import com.example.entity.BlogPic;
import com.example.entity.ShareEntity;
import com.example.huashangapp.BaseView;
import com.example.huashangapp.HSApplication;
import com.example.huashangapp.R;
import com.example.net.Communication;
import com.example.service.MainService;
import com.example.ui.contact.chat.L;
import com.example.ui.contact.chat.PushMessageReceiver;
import com.example.ui.contact.face.FaceUtil;
import com.example.ui.leftmenu.LeftMenuView;
import com.example.ui.leftmenu.MyListView;
import com.example.ui.leftmenu.MyListView.OnRefreshListener;
import com.example.ui.share.HomePageShareContentActivity;
import com.example.util.AsyncLoadImage;
import com.example.util.BitmapLoad;
import com.example.util.Util;

@SuppressLint("SimpleDateFormat")
public class HomePageView extends BaseView{
	private HSApplication hsApplication;
	private String myId;
	 
	private Context context;
	private Button leftBtn, rightBtn;
	private TextView title;
	public static MyListView listview;
//	private List<Map<String, Object>> shareList;
	public static List<ShareEntity> moreShareList;
	private LinearLayout pb;
	// 头布局文件
	private View headView;
	private View footView;
	private int listCountId=0;
//	private int lastItem;
	public static MyListViewAdapter homePageAdapter;
	public static HomePageGalleryAdapter hpgAdapter ;//= new HomePageGalleryAdapter(context,imgWallList);
	public static List<Map<String, Object>> imgWallList ;
	public static ImageView imgWall0Img;
	public static Gallery imgWall;
	private List<ImageView> imageViews;// 照片墙集合
	private FlowIndicator dots;//照片墙对应的点
//	private int currentItem = 0;// 当前图片的索引号
	public static ImageView headImg;
	private TextView myName;
	public static TextView introduceMyselfText;
	private EditText introduceMyselfEdit;
	private TextView footMoreBtn;
	private ProgressBar footLoadMoreLayout;
	
	private int pageSize=8;
	
	private String wallId;//背景墙id
	private String wallImgPath;//图片的路径
	public static String myIntroduce;//个性签名内容
	private String updateIntroduce;
	public  String headPath;

	// 系统键盘
	private InputMethodManager imm;

	public static final int MY_INFORMATION = 11;//我的资料
	public static final int SET_WALL_IMG = 12;//添加照片墙照片（没有的话）
	public static final int SET_WALL_GALLERY = 13;//添加照片墙照片（继续添加）
	public static final int SET_HEAD_IMG = 14;//头像
	public static final int GET_SIGNATURE = 15;//获取个性签名
	public static final int UPDATE_SIGNATURE = 16;//更新个性签名
	public static final int GET_MY_SHARE_CONTENT = 17;//查询我的分享
	public static final int GET_MY_MORE_SHARE_CONTENT = 18;//查询我的分享(更多)
	public static final int REFRESH = 19;//刷新
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	long dataTime;
	private String time;
	private int typeID;
	String[] imgPath = null;
	List<String> picList;
	List<BlogPic> blogImg;
	private AsyncLoadImage asyncLoadImage;
	//表情
	FaceUtil faceUtil = HSApplication.getInstance().getFaceUtil();
	
	public HomePageView(Context context, HSApplication application) {
		this.context = context;
		myId=HSApplication.sp.getString("userid","").toString();
		hsApplication=application;
		asyncLoadImage=new AsyncLoadImage();
		headPath=HSApplication.sp.getString("imgHead","").toString();
	}

	public static Handler handler ;
	public static Handler handler2 ;
	@SuppressLint("HandlerLeak")
	public void init() {
		
		view = LayoutInflater.from(context).inflate(R.layout.homepage, null);
		headView = LayoutInflater.from(context).inflate(R.layout.homepage_head,null);
		footView = LayoutInflater.from(context).inflate(R.layout.homepage_footer,null);
		imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
		findView();

		click();

		listView();
		
		gallery();
		
		handler = new Handler() {
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case 0:
					addImgWall();
					hpgAdapter = new HomePageGalleryAdapter(context,imgWallList);
					imgWall.setAdapter(hpgAdapter);
//					imgWall.setOnPageChangeListener(new MyPageChangeListener());
					pb.setVisibility(View.GONE);
					break;
				case 1:
					Util.toast(context, "网络连接有误");
					pb.setVisibility(View.GONE);
					break;
				case 2:
					//Util.toast(context, "图片已删除");
					break;
				case 3:
					Util.toast(context, "");
					break;
				case 4:
					//Util.toast(context, "图片已删除");
					break;
				case MY_INFORMATION:
					Intent intent = new Intent(context, MyInformationActivity.class);
					intent.putExtra("headPath", headPath);
					intent.putExtra("myId", myId);
					context.startActivity(intent);
					break;
				case SET_WALL_IMG:
					Intent wallImgIntent = new Intent(context,SetHomePageWallActivity.class);
					wallImgIntent.putExtra("wall", "wallImg");
					wallImgIntent.putExtra("myId", myId);
					context.startActivity(wallImgIntent);
					break;
				case SET_WALL_GALLERY:
					Intent wallGalleryIntent = new Intent(context,SetHomePageWallActivity.class);
					wallGalleryIntent.putExtra("wall", "wallGallery");
					wallGalleryIntent.putExtra("wallId", wallId);//图片id
					wallGalleryIntent.putExtra("wallImgPath", wallImgPath);//图片的路径
					wallGalleryIntent.putExtra("myId", myId);
					context.startActivity(wallGalleryIntent);
					break;
				case SET_HEAD_IMG:
					Intent headIntent = new Intent(context, SetHeadActivity.class);
					headIntent.putExtra("myId", myId);
					context.startActivity(headIntent);
					
					break;
				case GET_SIGNATURE:
					pb.setVisibility(View.GONE);
					if("false".equals(myIntroduce)){
						myIntroduce="";
					}
					introduceMyselfText.setText(myIntroduce.equals("") ? "写点东西介绍一下自己吧": myIntroduce);
					introduceMyselfEdit.setVisibility(View.GONE);
					introduceMyselfText.setVisibility(View.VISIBLE);
					imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
					break;
				case UPDATE_SIGNATURE:
					pb.setVisibility(View.GONE);
					introduceMyselfText.setText(updateIntroduce.equals("") ? "写点东西介绍一下自己吧": updateIntroduce);
					introduceMyselfEdit.setVisibility(View.GONE);
					introduceMyselfText.setVisibility(View.VISIBLE);
					imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
					break;
				case GET_MY_SHARE_CONTENT:
					pb.setVisibility(View.GONE);
					homePageAdapter = new MyListViewAdapter();
					listview.setAdapter(homePageAdapter);
					break;
				case GET_MY_MORE_SHARE_CONTENT:
					pb.setVisibility(View.GONE);
					List<ShareEntity> updateListData = moreShareList;
						 if(updateListData.size()!=0){
							 for(ShareEntity share:updateListData){
								 MainService.shareEntity.add(share);
							 }
								homePageAdapter.count+=updateListData.size();
								homePageAdapter.notifyDataSetChanged();
								footMoreBtn.setVisibility(View.VISIBLE);
								footLoadMoreLayout.setVisibility(View.GONE);
								
						 }else{
							 listview.removeFooterView(footView);
							 Util.toast(context, "数据加载完毕");
						 }
						 
					
					
					break;
				case 10:
					headPath=HSApplication.sp.getString("imgHead", "");
					asyncLoadImage.imageLoader.displayImage(headPath, headImg,asyncLoadImage.options);
					break;
				default:
					break;
				}
			};
		};
		
		//leone.xia add
		if(PushMessageReceiver.isPush==true){
			L.Debug("PushMessageReceiver.isPush", "run");
			PushMessageReceiver.isPush=false;
			myMoveView.showHideLeftMenu();
			listview.setEnabled(true);
		}

	}

	private void findView() {
		leftBtn = (Button) view.findViewById(R.id.layout_title_left_btn);
		title = (TextView) view.findViewById(R.id.layout_title_middle_text);
		rightBtn = (Button) view.findViewById(R.id.layout_title_right_btn);
		pb=(LinearLayout)view.findViewById(R.id.homepage_progressbar);
		listview = (MyListView) view.findViewById(R.id.homepage_introduce_listview);

		imgWall0Img=(ImageView)headView.findViewById(R.id.homepage_img_wall0_img);
		imgWall = (Gallery) headView.findViewById(R.id.homepage_img_wall);
		dots = (FlowIndicator) headView.findViewById(R.id.homepage_img_wall_dots);
//		imgWallNumText = (TextView) headView.findViewById(R.id.homepage_img_wall_num_text);
		headImg = (ImageView) headView.findViewById(R.id.homepage_head_img);
		myName=(TextView)headView.findViewById(R.id.homepage_name_text);
		introduceMyselfText = (TextView) headView.findViewById(R.id.homepage_introduce_myself_textview);
		introduceMyselfEdit = (EditText) headView.findViewById(R.id.homepage_introduce_myself_edit);
		footMoreBtn=(TextView)footView.findViewById(R.id.footer_more_btn);
		footMoreBtn.setClickable(true);
		footLoadMoreLayout=(ProgressBar)footView.findViewById(R.id.foot_load_more_layout);
		
		leftBtn.setText("菜单");
		title.setText(R.string.homepage);
		rightBtn.setText("我的资料");
		
		myName.setText(HSApplication.sp.getString("username","").toString());
		LeftMenuView.titleName.setText(myName.getText().toString());
		
		
		//获取头像
		Communication.getHead( myId);
		//获取用户签名
		Communication.getSignature(context, myId);
		
	}
	
	private void addImgWall() {
		
		imageViews = new ArrayList<ImageView>();
		// 初始化图片资源
		for (int i = 0; i < imgWallList.size(); i++) {
			ImageView imageView = new ImageView(context);
			try {
				String imgUrl = imgWallList.get(i).get("photo").toString();
				if(!"".equals(imgUrl)||imgUrl!=null){
					imageView.setImageBitmap(BitmapLoad.loadBitmap(context, imgUrl));
				}else{
					imageView.setImageResource(R.drawable.wall_bg);
				}
			} catch (Exception e) {
				imageView.setImageResource(R.drawable.wall_bg);
			}
			
			imageView.setScaleType(ScaleType.FIT_XY);
			imageViews.add(imageView);
		}
		dots.setCount(imageViews.size());// 设置点的数量
		
	}
	
	/*获取照片墙*/
	private void gallery() {
		
		Communication.getHomepageWall(context, myId);
		
        imgWall.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> parent, View v,
					int position, long id) {
				dots.setSeletion(position);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	/**
	 * 隐藏个性签名的输入框
	 * ----如果没改变内容，不请求，否则更新个性签名
	 */	
	private void hideIntroduceEdit(){
		if(myIntroduce.equals(introduceMyselfEdit.getText().toString().trim().toString())){
			introduceMyselfText.setText(myIntroduce);
			introduceMyselfEdit.setVisibility(View.GONE);
			introduceMyselfText.setVisibility(View.VISIBLE);
			imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
		}else{
			updateIntroduce = introduceMyselfEdit.getText().toString();
			Communication.updateSignature(context, myId, updateIntroduce);
		}
	}
	
	private void listView() {
		//getShare();
		listview.addHeaderView(headView);
		listview.addFooterView(footView);
		Communication.getMyShare(context, myId, listCountId);//请求数据
		
		listview.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				if(event.getAction() == MotionEvent.ACTION_DOWN && introduceMyselfEdit.getVisibility() == View.VISIBLE){
					hideIntroduceEdit();
					return true;
				}else{
					return false;
				}
			}
		});
		
		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if(introduceMyselfEdit.getVisibility()==View.VISIBLE){
					hideIntroduceEdit();
				}
				int position = arg2-2;
					Intent intent = new Intent(context, HomePageShareContentActivity.class);
					intent.putExtra("myId", myId);
					intent.putExtra("shareId", MainService.shareEntity.get(position).getId()+"");//分享的id
					intent.putExtra("type", MainService.shareEntity.get(position).getTypeId());//内容种类
					intent.putExtra("headImg", headPath);//头像
					intent.putExtra("name", MainService.shareEntity.get(position).getNickname());//姓名
					intent.putExtra("content", MainService.shareEntity.get(position).getTxt());//内容
					intent.putExtra("like", MainService.shareEntity.get(position).getLike()+"");//赞
					intent.putExtra("reply", MainService.shareEntity.get(position).getReply()+"");//评论
					intent.putExtra("forward", MainService.shareEntity.get(position).getForward()+"");//推荐
					
					List<String> img = new ArrayList<String>();
					List<BlogPic> bpImg = MainService.shareEntity.get(position).getPicList();
					for(int i=0;i<bpImg.size();i++){
						String pic = bpImg.get(i).getThumb().toString();
						img.add(pic);
					}
					int imgSize = img.size();
					String[] imgArr = (String[]) img.toArray(new String[imgSize]);
					intent.putExtra("imgArr", imgArr);//上传的图片数组
					
					if(typeID==1){
						try {
							long data1 =(long)MainService.shareEntity.get(position).getDateline();
							String originalTime = format.format(data1*1000);
							intent.putExtra("time", originalTime);//时间
							intent.putExtra("position",MainService.shareEntity.get(position).getLocation());//地理位置信息
						} catch (Exception e) {
							intent.putExtra("position","");//地理位置信息
							e.printStackTrace();
						}
					}else if(typeID==2){
						long data2 =(long)MainService.shareEntity.get(position).getModifytime();
						String modifyTime = format.format(data2*1000);
						intent.putExtra("time", modifyTime);//时间
						intent.putExtra("title", MainService.shareEntity.get(position).getTitle());
						intent.putExtra("forwardName", MainService.shareEntity.get(position).getForwardnickname());
						intent.putExtra("forwardTitle", MainService.shareEntity.get(position).getForwardtitle());
						intent.putExtra("originalName", MainService.shareEntity.get(position).getOrigintnickname());
					}
					
					context.startActivity(intent);
				
				
			}
		});
		
		footMoreBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				footMoreBtn.setVisibility(View.GONE);
				footLoadMoreLayout.setVisibility(View.VISIBLE);
				listCountId+=8;
				Communication.getMyShareMore(context, myId, listCountId,pageSize);
			}
		});
		
		listview.setonRefreshListener(new OnRefreshListener() {
			
			@Override
			public void onRefresh() {
				// TODO Auto-generated method stub
				new AsyncTask<Void, Void, Void>(){

					@Override
					protected Void doInBackground(Void... params) {
						// TODO Auto-generated method stub
						try {
							Thread.sleep(1500);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						gallery();
						//获取头像
						Communication.getHead(myId);
						//获取用户签名
						Communication.getSignature(context, myId);
						//请求数据
						Communication.getMyShare(context, myId, listCountId);
						return null;
					}
					
					@Override
					protected void onPostExecute(Void result) {
						homePageAdapter.notifyDataSetChanged();
						listview.onRefreshComplete();
					}
					
				}.execute(null,null,null);
				
				
			}
		});
		
		
		
	}
	
	private void click() {
		// 左边 “菜单” 按钮
		leftBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				myMoveView.showHideLeftMenu();
				if(MainService.isLeftMenu==true){
					listview.setEnabled(false);
				}else{
					listview.setEnabled(true);
				}
			}
		});
		// 右边 “我的资料” 按钮
		rightBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
//				Communication.queryMyMaterial(context, Communication.userID);
				Message msg = HomePageView.handler.obtainMessage(HomePageView.MY_INFORMATION);
				msg.what = HomePageView.MY_INFORMATION;
				msg.sendToTarget();
				
			}
		});
		// 自我介绍
		introduceMyselfText.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				introduceMyselfEdit.setVisibility(View.VISIBLE);
				introduceMyselfEdit.setText(introduceMyselfText.getText().toString());
				introduceMyselfText.setVisibility(View.GONE);
				introduceMyselfEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
				introduceMyselfEdit.setInputType(InputType.TYPE_CLASS_TEXT);

				introduceMyselfEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
					public boolean onEditorAction(TextView v,int actionId, KeyEvent event) {
						if (actionId == EditorInfo.IME_ACTION_DONE || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
							if(myIntroduce.equals(introduceMyselfEdit.getText().toString().trim().toString())){
								introduceMyselfText.setText(myIntroduce);
								introduceMyselfEdit.setVisibility(View.GONE);
								introduceMyselfText.setVisibility(View.VISIBLE);
								imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
							}else{
								updateIntroduce = introduceMyselfEdit.getText().toString();
								Communication.updateSignature(context, myId, updateIntroduce);
							}
							
									
							return true;
						}
						return false;
					}
				});
			}
		});

		/**
		 * 默认背景图片的点击事件
		 */
		imgWall0Img.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Message msg = handler.obtainMessage(SET_WALL_IMG);
				msg.what = SET_WALL_IMG;
				msg.sendToTarget();
			}
		});
		
		/**
		 * 用户自己添加的背景图片点击事件
		 */
		imgWall.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View v, int position,
					long id) {
				wallId=imgWallList.get(position).get("id").toString();
				wallImgPath = imgWallList.get(position).get("photo").toString();
				Message msg = handler.obtainMessage(SET_WALL_GALLERY);
				msg.what = SET_WALL_GALLERY;
				msg.sendToTarget();
			}
		});
		
		/**
		 * 用户头像的点击事件
		 */
		headImg.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Message msg = handler.obtainMessage(SET_HEAD_IMG);
				msg.what = SET_HEAD_IMG;
				msg.sendToTarget();
			}
		});

	}

	public class MyListViewAdapter extends BaseAdapter {
		int count = MainService.shareEntity.size();
		
		@Override
		public int getCount() {
			if(count<8){
				footMoreBtn.setVisibility(View.GONE);
			}
			return count;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return MainService.shareEntity.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@SuppressLint({ "UseValueOf", "SimpleDateFormat" })
		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.homepage_listview_item_whole, null);
				holder = new ViewHolder();
				holder.headImg=(ImageView) convertView.findViewById(R.id.share_photo_item_avatar);
				holder.name=(TextView) convertView.findViewById(R.id.share_photo_item_name);
				holder.time=(TextView) convertView.findViewById(R.id.share_photo_item_time);
				holder.comment_count=(TextView) convertView.findViewById(R.id.share_photo_item_comment_count);
				holder.like_count=(TextView) convertView.findViewById(R.id.share_photo_item_like_count);
				holder.photoItemLayot=(LinearLayout)convertView.findViewById(R.id.share_photo_item_layout);
				
				//// typeId = 1 （原创）//////////////////////////////////////////////////////////////////////////////////////
				holder.original = (View) convertView.findViewById(R.id.original_layout);
				holder.original_content_text=(TextView) convertView.findViewById(R.id.share_photo_item_original_content_text);
				holder.original_content_photo1=(ImageView) holder.original.findViewById(R.id.share_photo_item_original_content_photo1);
				holder.original_content_photo2=(ImageView) holder.original.findViewById(R.id.share_photo_item_original_content_photo2);
				holder.original_content_photo3=(ImageView) holder.original.findViewById(R.id.share_photo_item_original_content_photo3);
				holder.original_location = (TextView) holder.original.findViewById(R.id.share_photo_item_from);
				
				//// typeId = 2 （推荐、或、转发、或、分享）//////////////////////////////////////////////////////////////////////////////////////
				holder.transition = (View) convertView.findViewById(R.id.transition_layout);
				holder.forwardTitleLayot=(LinearLayout)holder.transition.findViewById(R.id.forward2_title_layout);
				holder.transition_original_name=(TextView)holder.transition.findViewById(R.id.share_photo_item_transition_original_name);
				holder.transition_title = (TextView) holder.transition.findViewById(R.id.share_photo_item_titie);
				holder.transition_name2= (TextView) holder.transition.findViewById(R.id.share_photo_item_name2);
				holder.transition_title2= (TextView) holder.transition.findViewById(R.id.share_photo_item_title2);
				holder.transition_content_text=(TextView) convertView.findViewById(R.id.share_photo_item_transition_content_text);
				holder.transition_content_photo1=(ImageView) holder.transition.findViewById(R.id.share_photo_item_transition_content_photo1);
				holder.transition_content_photo2=(ImageView) holder.transition.findViewById(R.id.share_photo_item_transition_content_photo2);
				holder.transition_content_photo3=(ImageView) holder.transition.findViewById(R.id.share_photo_item_transition_content_photo3);
				
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			
				//Bitmap headBit = BitmapLoad.loadBitmap(context, headPath);
				//holder.headImg.setImageBitmap(headBit);//头像
				holder.name.setText(MainService.shareEntity.get(position).getNickname());//名字
				headPath=HSApplication.sp.getString("imgHead", "");
				asyncLoadImage.imageLoader.displayImage(headPath, headImg,asyncLoadImage.options);
				
				
				String commentCount = MainService.shareEntity.get(position).getReply() +"";
				String listCount = MainService.shareEntity.get(position).getLike()+"";
				holder.comment_count.setText("评论 "+(commentCount==""?"0":commentCount));//评论数量
				holder.like_count.setText("赞 "+(listCount==""?"0":listCount));//赞的数量
			
				picList = new ArrayList<String>();
				blogImg=MainService.shareEntity.get(position).getPicList();
				for(int i=0;i<blogImg.size();i++){
					String pic = blogImg.get(i).getThumb().toString();
					picList.add(pic);
				}
				
				int size = picList.size();
				imgPath = (String[]) picList.toArray(new String[size]);
				
				typeID = MainService.shareEntity.get(position).getTypeId();
				String contentStr = MainService.shareEntity.get(position).getTxt().toString().replaceAll("&prime;", "'");
				switch (typeID) {
				case 1://默认1：原创
					holder.original.setVisibility(View.VISIBLE);
					holder.transition.setVisibility(View.GONE);
					try {
						dataTime = (long)MainService.shareEntity.get(position).getDateline();
						time = format.format(dataTime*1000);
						holder.time.setText(time==""?"":Util.DateCompare(time));//原创时间
					} catch (ParseException e) {
						holder.time.setText("");
						e.printStackTrace();
					}
					holder.original_content_text.setText(
				    		faceUtil.convertNormalStringToSpannableString(contentStr),
							BufferType.SPANNABLE);
					
					String myLocation = MainService.shareEntity.get(position).getLocation();
					if(!"".equals(myLocation)&&myLocation!=null){
						holder.original_location.setText(myLocation);
					}else{
						holder.original_location.setVisibility(View.GONE);
					}
					originalImageView(holder,imgPath);//图片
					break;
				case 2://2：推荐  或  分享   或   转发
					holder.original.setVisibility(View.GONE);
					holder.transition.setVisibility(View.VISIBLE);
					holder.transition_title.setText(MainService.shareEntity.get(position).getTitle());
					if("".equals(MainService.shareEntity.get(position).getForwardnickname())||
							MainService.shareEntity.get(position).getForwardnickname()==null){
						holder.forwardTitleLayot.setVisibility(View.GONE);
					}else{
						holder.transition_name2.setText(MainService.shareEntity.get(position).getForwardnickname());
						holder.transition_title2.setText(MainService.shareEntity.get(position).getForwardtitle());
					}
					holder.transition_original_name.setVisibility(View.GONE);
					holder.transition_content_text.setText(MainService.shareEntity.get(position).getOrigintnickname()+":"+
									faceUtil.convertNormalStringToSpannableString(contentStr),BufferType.SPANNABLE);
					try {
						dataTime =(long)MainService.shareEntity.get(position).getModifytime();
						time = format.format(dataTime*1000);
						holder.time.setText(time==""?"":Util.DateCompare(time));//转发时间
					} catch (ParseException e) {
						holder.time.setText("");
						e.printStackTrace();
					}
					transitionImageView(holder,imgPath);
					break;

				default:
					break;
				}
			
			
			return convertView;
		}

		private void originalImageView(ViewHolder holder,String[] imgPath) {
			if(imgPath!=null){
				try {
					switch (imgPath.length) {
					case 0:
						holder.original_content_photo1.setVisibility(View.GONE);
						holder.original_content_photo2.setVisibility(View.GONE);
						holder.original_content_photo3.setVisibility(View.GONE);
						break;
					case 1:
						holder.original_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[0]));
						holder.original_content_photo2.setVisibility(View.GONE);
						holder.original_content_photo3.setVisibility(View.GONE);
						break;
					case 2:
						holder.original_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[0]));
						holder.original_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[1]));
						holder.original_content_photo3.setVisibility(View.GONE);
						break;
					default:
						holder.original_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[0]));
						holder.original_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[1]));
						holder.original_content_photo3.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[2]));
						break;
					}
				} catch (Exception e) {
					Util.toast(context, "图片加载失败");
					e.printStackTrace();
				}
			}else{
				holder.original_content_photo1.setVisibility(View.GONE);
				holder.original_content_photo2.setVisibility(View.GONE);
				holder.original_content_photo3.setVisibility(View.GONE);
			}
		}
		
		private void transitionImageView(ViewHolder holder,String[] imgPath) {
			if(imgPath!=null){
				try {
					switch (imgPath.length) {
					case 0:
						holder.transition_content_photo1.setVisibility(View.GONE);
						holder.transition_content_photo2.setVisibility(View.GONE);
						holder.transition_content_photo3.setVisibility(View.GONE);
						break;
					case 1:
						holder.transition_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[0]));
						holder.transition_content_photo2.setVisibility(View.GONE);
						holder.transition_content_photo3.setVisibility(View.GONE);
						break;
					case 2:
						holder.transition_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[0]));
						holder.transition_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[1]));
						holder.transition_content_photo3.setVisibility(View.GONE);
						break;
					default:
						holder.transition_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[0]));
						holder.transition_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[1]));
						holder.transition_content_photo3.setImageBitmap(BitmapLoad.loadBitmap(context, imgPath[2]));
						break;
					}
				} catch (Exception e) {
					Util.toast(context, "图片加载失败");
					e.printStackTrace();
				}
			}else{
				holder.transition_content_photo1.setVisibility(View.GONE);
				holder.transition_content_photo2.setVisibility(View.GONE);
				holder.transition_content_photo3.setVisibility(View.GONE);
			}
		}
		

		class ViewHolder {
			//不变的
			ImageView headImg;//头像
			TextView name;//名字
			TextView time;//时间
			TextView comment_count;//评论数量
			TextView like_count;//赞数量
			
			View original;//原创的
//			TextView original_title;
			TextView original_all;
			TextView original_location;
			TextView original_content_text;//正文内容
			ImageView original_content_photo1;//图片1
			ImageView original_content_photo2;//图片2
			ImageView original_content_photo3;//图片3

			
			View transition;//转发的
			LinearLayout photoItemLayot;
			LinearLayout forwardTitleLayot;//二级推荐布局
			TextView transition_original_name;//原创者姓名
			TextView transition_title;
			TextView transition_name2;
			TextView transition_title2;
			TextView transition_content_text;//正文内容
			ImageView transition_content_photo1;//图片1
			ImageView transition_content_photo2;//图片2
			ImageView transition_content_photo3;//图片3
		}

	}

}
